package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.BlackList;
import com.itheima.mapper.BlackListMapper;
import com.itheima.service.db.BlackListService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListServiceImpl implements BlackListService {

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public PageBeanVo findByPage(Long userId, Integer pageNum, Integer pageSize) {
        // 1.开启分页
        Page<BlackList> page = new Page<>(pageNum, pageSize);
        //2. 构建条件
        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlackList::getUserId,userId);
        //3. 分页查询
        page=blackListMapper.selectPage(page,queryWrapper);
        //4.封装pageBeanVo
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    @Override
    public void delete(Long userId, Long blackUserId) {
       //1. 构建条件
        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlackList::getUserId,userId);
        queryWrapper.eq(BlackList::getBlackUserId,blackUserId);
        //2. mapper删除
        blackListMapper.delete(queryWrapper);
    }
}
